package com.hgk.wanwan.main.fragment.whatfragment.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

import com.hgk.wanwan.main.fragment.whatfragment.model.BannerBean;

import java.util.List;

import width.hgk.wanwan.R;

/**
 * Created by lenovo on 2016/10/14.
 */
public class BannerAdapter extends BaseAdapter {
    private List<BannerBean> bannerLists;
    private List<Integer> mLists;
    private Context context;
//    private ImageLoader imageLoader;
//    private DisplayImageOptions displayImageOptions;

    public BannerAdapter(List<Integer> bannerLists, Context context) {
        this.mLists = bannerLists;
        this.context = context;
//        imageLoader = ImageLoader.getInstance();
//        displayImageOptions = LoadImageDisplayOption.getDefaultPic(R.drawable.pic_one);
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public Object getItem(int position) {
//        return bannerLists.get(position%bannerLists.size());
        return mLists.get(position%mLists.size());
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView==null){
            vh = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.image,null);
            Gallery.LayoutParams params = new Gallery.LayoutParams(Gallery.LayoutParams.WRAP_CONTENT,Gallery.LayoutParams.WRAP_CONTENT);
            convertView.setLayoutParams(params);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        vh.mPic = (ImageView) convertView.findViewById(R.id.iv_single);
        vh.mPic.setScaleType(ImageView.ScaleType.CENTER_CROP);
//        try{
//            if (displayImageOptions!=null){
//                imageLoader.displayImage(bannerLists.get(position%bannerLists.size()).getPics(),vh.mPic,displayImageOptions);
                vh.mPic.setImageResource(mLists.get(position%mLists.size()));
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//        }
        return convertView;
    }
    public class ViewHolder{
        private ImageView mPic;

    }
}
